/*
 * @Author: Marte
 * @Date:   2016-10-24 16:31:21
 * @Last Modified by:   Marte
 * @Last Modified time: 2016-10-31 09:26:22
 */

'use strict';

var sequelizeService = require('../utils/sequelizeService');

var Type = sequelizeService.models.Type;

var _ = require('underscore');
var Promise = require('bluebird');

var controller = {

};

/**
 * [getJsonAll 获取证件类型]
 * @param  {[type]}   req  [description]
 * @param  {[type]}   res  [description]
 * @param  {Function} next [description]
 * @return {[type]}        [description]
 */
controller.getJsonAll = function(req, res, next) {
    var getTypes = Type.fetch();

    getTypes
        .then(function(types) {
            return res.status(200).json(types);
        })
        .error(function(err) {
            return res.status(400).json({
                error: '读取数据出错！',
                syserror: err.message
            });
        })
        .catch(function(err) {
            return res.status(500).json({
                error: '读取数据出错！',
                syserror: err.message
            });
        });
};

controller.registerPath = function(router) {

    /*获取所有证件类型*/
    router.addPathGetHanlder('/api/types', controller.getJsonAll);

};

module.exports = controller;
